package logic

import (
	"context"
	"users/usersrpc/usersrpc"

	"users/api/internal/svc"
	"users/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAuthLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAuthLogic {
	return &UserAuthLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserAuthLogic) UserAuth(req *types.UserAuthRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	auth, err := l.svcCtx.UsersRpc.UserAuth(l.ctx, &usersrpc.UserAuthRequest{
		UserId:   req.UserId,
		IdCard:   req.IdCard,
		RealName: req.RealName,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "实名认证成功",
		Code:    200,
		Data:    auth,
	}, nil
}
